package test;

import java.util.ArrayList;

/**
 * Created by Caesar on 2016/4/15.
 */
public class Dice {
    ArrayList<ArrayList<Integer>> result = new ArrayList<>();
    private int num = 0;

    public void dice(int n, int sum, ArrayList<Integer> parants) {
        num++;
        if (parants == null)
            parants = new ArrayList<>();
        if (n == 1) {
            parants.add(sum);
            result.add(parants);
            return;
        }
        for (int i = 6; i > 0; i--) {
            if ((n - 1) * 6 > sum - i && sum - i > (n - 1)) {
                ArrayList<Integer> thisarr = new ArrayList<>(parants);
                thisarr.add(i);
                dice(n - 1, sum - i, thisarr);
            } else
                continue;
        }
    }

    public void dice2(int n, int sum, ArrayList<Integer> parants) {
        num++;
        if (parants == null)
            parants = new ArrayList<>();
        if (n == 1) {
            parants.add(sum);
            result.add(parants);
            return;
        }
        for (int i = 1; i < 7; i++) {
            if ((n - 1) * 6 > sum - i && sum - i > (n - 1)) {
                ArrayList<Integer> thisarr = new ArrayList<>(parants);
                thisarr.add(i);
                dice2(n - 1, sum - i, thisarr);
            } else
                continue;
        }
    }

    public static void main(String[] args) {
        Dice dice = new Dice();
        dice.dice(4, 20, null);
        System.out.println(dice.result+"    "+dice.result.size());
        System.out.println(dice.num);
    }
}
